package com.tedu.element.player;

import com.tedu.element.Direction;

import java.awt.event.KeyEvent;
import java.util.Set;

/**
 * 玩家2的输入策略 (WASD + B)
 */
public class P2InputStrategy implements PlayerInputStrategy {

    @Override
    public void handleInput(Player player, Set<Integer> pressedKeys) {
        // 根据按键集合更新移动状态
        player.setMoveUp(pressedKeys.contains(KeyEvent.VK_W));
        player.setMoveDown(pressedKeys.contains(KeyEvent.VK_S));
        player.setMoveLeft(pressedKeys.contains(KeyEvent.VK_A));
        player.setMoveRight(pressedKeys.contains(KeyEvent.VK_D));

        // 更新方向
        if (player.isMoveUp()) {
            player.setDirection(Direction.up);
        }
        if (player.isMoveDown()) {
            player.setDirection(Direction.down);
        }
        if (player.isMoveLeft()) {
            player.setDirection(Direction.left);
        }
        if (player.isMoveRight()) {
            player.setDirection(Direction.right);
        }

        // 更新放置泡泡
        player.setPlaceBubble(pressedKeys.contains(KeyEvent.VK_B));
    }
}
